import {
    getDictTreeData
  } from "@/api/common.js";
  import {undoListData} from '@/api/workStation/workStation.js'
  //整理数据字典data
  const fmDictData = (data) => {
    var obj = new Object();
    if (data) {
      data.map((i) => {
        if (i.sysDataDictDetailList) {
          obj[i.code] = i.sysDataDictDetailList;
          Object.assign(obj, fmDictData(i.sysDataDictDetailList));
        }
      });
    }
    return obj;
  };
  
  const commonData = {
    state: {
      //dictData: {}, //数据字典数据
      undoData:{},//待办数据
    },
    mutations: {
      SET_DICTDATA: (state, data) => {
        state.dictData = fmDictData(data);
      },
      SET_UNDODATA: (state, data) => {
        state.undoData = data;
      },
    },
    actions: {
      // GetDictData({
      //   commit
      // }) {
      //   return new Promise((resolve, reject) => {
      //     Promise.all([getDictTreeData()]).then(res => {
      //         let dictData = res[0].data || [];
      //         commit("SET_DICTDATA", dictData);
      //         resolve(true);
      //       })
      //       .catch((error) => {
      //         reject(error);
      //       });
      //   });
      // },
      GetUndoData({
        commit
      }) {
        return new Promise((resolve, reject) => {
          Promise.all([undoListData()]).then(res => {
              let undoData = res.data || [];
              commit("SET_UNDODATA", undoData);
              resolve(true);
            })
            .catch((error) => {
              reject(error);
            });
        });
      },
    },
  };
  export default commonData;